//This class is the base class from which the other
//  classes and forms are called and displayed.

#include "basewindow.h"
#include "ui_basewindow.h"
#include <QDateTime>

BaseWindow::BaseWindow(QWidget *parent, QString filepathString) :
    QMainWindow(parent),
    filepath(filepathString),
    sound(true),
    invertUpDown(true),
    ui(new Ui::BaseWindow)
{
    ui->setupUi(this);
    //log the date and time
    QDateTime dt;
    this->logEvent(dt.currentDateTime().toString());
}

BaseWindow::~BaseWindow()
{
    delete ui;
}

//Basic method for running the game.
void BaseWindow::runGame()
{
    showMainMenu();
}

//Display the main menu.
int BaseWindow::showMainMenu()
{
    MainMenu *menu = new MainMenu(this, filepath);
    menu->show();
}

//Display the main gameplay area (start the game).
int BaseWindow::showMainWindow(QString command)
{
    MainWindow *game = new MainWindow(this, filepath, command);
    game->show();
}

int BaseWindow::showGameOver(bool highScore, int speed)
{
    GameOver *end = new GameOver(this, filepath, highScore, speed);
    end->show();
}

void BaseWindow::toggleSound()
{
    sound ^= true;
}

void BaseWindow::toggleInvertUpDown()
{
    invertUpDown ^= true;
}

//Logs the event for an action
void BaseWindow::logEvent(QString entry)
{
    QFile file(filepath + "/gameData/eventLog.txt");
    file.open(QIODevice::Append | QIODevice::Text);
    QTextStream inOut(&file);
    inOut << entry << endl;
    //file.close();
}
